package com.controller;

import com.model.MyEcharts;
import com.model.MyLog;
import com.service.MylogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api("LOG")
@RestController
@RequestMapping("/mylog")

public class MylogController {
    @Autowired
    private MylogService mylogService;

    @CrossOrigin
    @RequestMapping(value = "/addLog",produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public int addLog(@RequestBody MyLog myLog){
        System.out.println("进入用户添加方法");
        return mylogService.addMylog(myLog);
    }

    @CrossOrigin
    @RequestMapping(value = "/updateLog",produces ="application/json;charset=utf-8",method = RequestMethod.PUT)
    public int updateLog(@RequestBody MyLog mylog){
        System.out.println("进入用户修改方法，修改的主键为："+mylog.getUserID());
        return mylogService.updateMyLog(mylog);
    }

    @CrossOrigin
    @RequestMapping(value = "/deleteLog",produces ="application/json;charset=utf-8",method = RequestMethod.GET)
    public int deleteMyLog(@RequestBody int userID){
        System.out.println("进入删除用户信息，主键为："+userID);
        return mylogService.deleteMyLog(userID);
    }

    @CrossOrigin
    @RequestMapping(value = "/getLog",produces ="application/json;charset=utf-8",method = RequestMethod.GET)
    public MyLog getlog(@RequestBody int userID){
        System.out.println("进入根据主键查找信息，主键为："+userID);
        return mylogService.getLog(userID);
    }

    @CrossOrigin
    @ApiOperation(value = "Echart")
    @RequestMapping(value = "/getEcharts", produces ="application/json;charset=utf-8",method = RequestMethod.PUT)
    public List<MyEcharts> getEcharts(@RequestBody MyLog mylog){
        System.out.println("进入用户查询方法");
        System.out.println(mylog.getDotime());
        List<MyEcharts> myEcharts=mylogService.EchartsMyLogStart(mylog);
        System.out.println(myEcharts.size());
        return myEcharts;
    }

    @CrossOrigin
    @RequestMapping(value = "/getAll",produces ="application/json;charset=utf-8",method = RequestMethod.PUT)
    public List<MyLog> getAll(@RequestBody MyLog mylog){
        System.out.println("进入查询");
        List<MyLog> myLogList = mylogService.getAllMyLogs(mylog);
        System.out.println(myLogList.size());
        return myLogList;
    }

    @CrossOrigin
    @ApiOperation(value = "getlog10")
    @RequestMapping(value = "/Echarts10", produces = "application/json;charset=utf-8" ,method = RequestMethod.PUT)
    List<MyEcharts> Echarts10(@RequestBody MyLog myLog) {
        System.out.println(myLog.toString());
        List<MyEcharts> eCharts=MylogService.Echarts10(myLog);
        System.out.println(eCharts.size());
        return eCharts;
    }

}